package com.gitee.fdc.web.page;

import java.io.Serializable;
import com.gitee.fdc.kits.StrKit;

/**
 * @author liuzh
 * @since 2017/7/26.
 */
public class PageReq implements Serializable {

    private static final long serialVersionUID = -1524970970794892969L;

    private Integer limit = 10;
    private Integer offset = 0;
    private String sort;
    private String order;
    private boolean openSort;// = true;
    private boolean asc;

    public PageReq() {
    }

    public PageReq(Integer limit, Integer offset, String sort, String order) {
        this.limit = limit;
        this.offset = offset;
        this.sort = sort;
        this.order = order;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }

    public Integer getOffset() {
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getPage() {
        
        return (int) Math.floor(this.offset / this.limit);
    }

    public String getSort() {
        return sort;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public boolean isOpenSort() {
        return openSort;
    }

    public void setOpenSort(boolean openSort) {
        this.openSort = openSort;
    }

    public boolean isAsc() {
        return asc;
    }

    public void setAsc(boolean asc) {
        this.asc = asc;
    }

    public String getOrderBy() {
        if (StrKit.isNotEmpty(sort) && StrKit.isNotEmpty(this.order)) {
            return this.sort.concat(" ").concat(this.order);
        } else {
            return " ";
        }
    }
}
